package aws;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 取出一个数的每一位, ^2
 * 直到这个数为1
 */
public class HappyNum {

    private List<Integer> happyNum(int num) {
        List<Integer> happyNums = new ArrayList<>();
        happyNums.add(num);
        do{
            List<Integer> nums = splitNum(num);
            int temp = 0;
            for(int i=0; i<nums.size() ; i++) {
                temp = temp + nums.get(i) ^2;
            }
            num = temp;
            happyNums.add(temp);
        } while (num != 1);

        happyNums.stream().forEach(item ->{
            System.out.print(item + " ");
        });

        return happyNums;

    }

    private List<Integer> splitNum(int num) {
        List<Integer> list = new ArrayList<>();
        while (num != 0) {
            int yu = num % 10;
            num = num / 10;
            list.add(yu);
        }
        Collections.reverse(list);
        return list;
    }

    public static void main(String[] args) {

        System.out.println(1^2);
        System.out.println(9^2);
       // new HappyNum().happyNum(19);
    }

}
